import { Suspense } from 'react'
import { Switch, Route, Redirect } from 'react-router-dom'

function Routerviews(props) {
  const { routlinks } = props
  const routerlists = routlinks.filter((item) => {
    return !item.to
  })
  const redirects = routlinks.filter((item) => {
    return item.to
  })[0]
  console.log(routerlists, redirects);
  return (
    <div className='router_warp'>
      <Suspense>
        <Switch>
          {
            routerlists && routerlists.length ? routerlists.map((item, index) => {
              return <Route key={index} path={item.path} render={(routerProps) => {
                if (item.children) {
                  return <item.component {...routerProps} child={item.children}></item.component>
                }
                return <item.component {...routerProps}></item.component>
              }}></Route>
            }) : '暂无路由数据'
          }
          {
            redirects ? <Redirect from={redirects.from} to={redirects.to}></Redirect> : '暂无重定此向'
          }
        </Switch>
      </Suspense>
    </div>
  )
}
export default Routerviews